package com.vmtest;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
//import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
//import android.widget.ViewFlipper;

import com.vmtest.R;
 
public class frmPpal extends Activity {
	
	final Context context = this;	
	
	// Evento al usar el boton de retorno
		@Override
		public void onBackPressed() {
			
		    // do something on back.
			//this.startActivity(new Intent(frmficheros.this,frmPpal.class));
			
			// custom dialog
					final Dialog dialog = new Dialog(context);
					dialog.setContentView(R.layout.dialogmenu);
					dialog.setTitle("Menu Principal");

					// set the custom dialog components - text, image and button
					TextView text = (TextView) dialog.findViewById(R.id.text);
					text.setText("¿Desea salir de la aplicacion?");
					
					//personalizacion de imagen
					//ImageView image = (ImageView) dialog.findViewById(R.id.image);
					//image.setImageResource(R.drawable.ic_launcher);

					Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
					Button dialogButton1 = (Button) dialog.findViewById(R.id.dialogButtonCANCEL);
					// if button is clicked, close the custom dialog
					dialogButton.setOnClickListener(new OnClickListener() {
						public void onClick(View v) {
							//dialog.dismiss();
							Intent intentlogin = new Intent(frmPpal.this, LoginActivity.class);
	                		   startActivity(intentlogin); 
	                	       //finishFromChild(getParent());
	                	       moveTaskToBack(true);
						}
					});
					
					dialogButton1.setOnClickListener(new OnClickListener() {
						public void onClick(View v) {
							dialog.dismiss();
						}
					});


					dialog.show();
			
		    return;
		}
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
		setContentView(R.layout.frmppal);
				
		 
		ListView l = (ListView) findViewById(R.id.listView1);
			 
		l.setAdapter(new miAdapter(this));		
		
		l.setOnItemClickListener(new OnItemClickListener() {				                	
			
			// direccionamiento de items menu
            public void onItemClick(AdapterView<?> parent, View v, int posicion, long id) {
            	
            	/*ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
                vf.setAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.push_left_in));           	               
                vf.setDisplayedChild(posicion);*/
            	          	
                	switch (posicion){
                	case 0:
                		Intent intentfic = new Intent(frmPpal.this, frmficheros.class);
                		startActivity(intentfic); 
                		break;
                	case 1:
                		Intent intentprev = new Intent(frmPpal.this, frmprevisitas.class);
                		startActivity(intentprev); 
                		break;
                	case 2:
                		Intent intentpost = new Intent(frmPpal.this, frmpostvisitas.class);
                		startActivity(intentpost); 
                		break;
                	case 3:
                		Intent intentnotif = new Intent(frmPpal.this, frmnotificaciones.class);
                		startActivity(intentnotif); 
                		break;  
                	case 4:
                		Intent intentrep = new Intent(frmPpal.this, frmreportes.class);
                		startActivity(intentrep); 
                		break;  
                	case 5:
                		Intent intentaus = new Intent(frmPpal.this, frmausencias.class);
                		startActivity(intentaus); 
                		break;  
                	case 6:
                		Intent intentsinc = new Intent(frmPpal.this, frmsincronizar.class);
                		startActivity(intentsinc); 
                		break;  
                	case 7:
                		Intent intentconf = new Intent(frmPpal.this, frmconfiguracion.class);
                		startActivity(intentconf); 
                		break;  
                	case 8:
                		//onRestart();
//                		Intent intentlogin = new Intent(frmPpal.this, LoginActivity.class);
//                		   startActivity(intentlogin); 
//                	       finishFromChild(getParent());
//                	       moveTaskToBack(true);
                		onBackPressed();
                		break;  
                	}
            }
        });
		                                                     
    }
    
/*	@Override
    protected void onRestart() {
       // TODO Auto-generated method stub
	   Intent intentlogin = new Intent(frmPpal.this, LoginActivity.class);
	   startActivity(intentlogin); 
       finishFromChild(getParent());
       moveTaskToBack(true);
  }*/
    

	private static class miAdapter extends BaseAdapter {
 
		private LayoutInflater mInflater;
 
		private static final String[][] data = {{"Ficheros","1"}, {"PreVisitas","2"}, {"PostVisitas","3"}, {"Notificaciones","4"}, {"Reportes","5"}, {"Ausencias","6"}, {"Sincronizar","7"}, {"Configuracion","8"}, {"Salir","9"}};
		
		private static final int[][] dataimg =  {{R.drawable.icono,1},{R.drawable.icono1,2},{R.drawable.icono2,3},{R.drawable.icono3,4},{R.drawable.icono4,5},{R.drawable.icono5,6},{R.drawable.icono6,7},{R.drawable.icono7,8},{R.drawable.icono8,9}};
		
 
		public miAdapter(Context context) {
 
			mInflater = LayoutInflater.from(context);						
	    
		}
		
		
		public View getView(int position, View convertView, ViewGroup parent) {
 
 
			TextView text;
 
			ImageView img1;
 
 
			if (convertView == null) {
 
				convertView = mInflater.inflate(R.layout.listview_fila, null);				
 
			} 
 
			text = (TextView) convertView.findViewById(R.id.TextView01);
  
			img1 = (ImageView) convertView.findViewById(R.id.ImageView01);
 
			text.setText(data[position][0]);
 
			//img1.setImageResource(R.drawable.icono);			
			img1.setImageResource(dataimg[position][0]);
 
			return convertView;
 
		}
 
 
		public int getCount() { 
			return data.length; 
		}
 
 
		public Object getItem(int position) { 
			return position; 
		}
 
 
		public long getItemId(int position) { 
			return position; 
		}		    
				
	}
		
}

